package com.suncaper.tddmall.service;

import com.suncaper.tddmall.common.model.User;
import com.suncaper.tddmall.common.model.UserExample;
import com.suncaper.tddmall.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    @Autowired

    UserMapper userMapper;
    public User login(String name,String password) {
        UserExample example = new UserExample();
        example.createCriteria().andUsernameEqualTo(name).andPasswordEqualTo(password);
        List<User> users = userMapper.selectByExample(example);
        return users.size() > 0 ? users.get(0) : null;
    }


        public void register(User user) {
            userMapper.insertSelective(user);
        }

        public User findByUsername(String username) {

            return userMapper.findByUsername(username);

        }

    public void registerUser(User user){

        userMapper.registerUser(user);
    }



}
